﻿using System.ComponentModel;
using Hn.Database.DAL;
using Hn.Database.Enum;
using SuperSocket.Command;

namespace MSocketCore.MSocket
{
    public class MyCmdFilter : CommandFilterAttribute
    {
        //private readonly ILogger<MyCmdFilter> _logger;

        //public MyCmdFilter(ILogger<MyCmdFilter> logger)
        //{
        //    _logger = logger;
        //}

        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
        }

        public override bool OnCommandExecuting(CommandExecutingContext commandContext)
        {
            var sn = ((MyPackage)commandContext.Package).Sn;
            var des = ((MySession) commandContext.Session);
            if (!string.IsNullOrEmpty(sn))
            {
                if (string.IsNullOrEmpty(des.Sn))
                {
                    des.Sn = sn;
                }
                DtuDAL.UpdateOnline(sn, OnlineType.Online);
            }
            //var v = (DescriptionAttribute[]) commandContext.CurrentCommand.GetType()
            //    .GetCustomAttributes(typeof(DescriptionAttribute), false);
           
            return true;
        }
    }
}